package com.park.config;

import com.park.interceptor.ChangePassInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    public static final String IMAGE_PATH="/img/";
    public static final String IMAGE_DIR="D:\\JAVATrain\\images\\";

    @Autowired
    ChangePassInterceptor changePassInterceptor;


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(IMAGE_PATH+"**").addResourceLocations("file:"+IMAGE_DIR);
    }

    /**
     * 配置拦截器，让拦截器生效
     * @param registry
     */
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/dologin");
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(changePassInterceptor).addPathPatterns("/dologin");
    }
}

